package cn.javadog.smartbreeding.record.converter;


import cn.javadog.smartbreeding.core.dto.WeightRecordDTO;
import cn.javadog.smartbreeding.record.entity.WeightRecord;
import org.mapstruct.Mapper;

/**
 * @author 余勇
 */
@Mapper(componentModel="spring")
public interface WeightRecordConverter extends BaseConverter<WeightRecordDTO, WeightRecord,WeightRecordDTO> {

	@Override
	default WeightRecord dto2entity(WeightRecordDTO dto){
		return new WeightRecord()
			.setEntryTime(dto.getEntryTime())
			.setSampleValueList(dto.getValues().toString()
				.replace("[","").replace("]",""))
			.setShedNo(dto.getShedNo())
			.setValue((int) dto.getValues().stream().mapToInt(t->t).average().getAsDouble());


	}
}
